<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/extjs/include/all.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js"></script>
<title>登录页面</title>
<%
	//移除session中的用户信息
	session.removeAttribute("__SATURN_AUTORITY_USER__");
%>
<script type="text/javascript">
if(window != window.parent){
	window.parent.location = window.location;
}

Ext.onReady(function(){

	if('<%=session.getAttribute("__LOGIN_ERROR_MESSAGE__")%>'!='null'){
		Ext.MessageBox.alert('警告','<%=(String)session.getAttribute("__LOGIN_ERROR_MESSAGE__")%>');
	}
	
    Ext.QuickTips.init();
  
    var loginForm = new Ext.FormPanel({ 
    	id:'loginForm',
        labelWidth: 80,
        frame: true, 
        title: '欢迎登录Saturn平台管理系统', 
        defaultType: 'textfield',
		monitorValid: true,
		keys:[{ 
			key: [13], 
			fn:login 
		}],
        items: [{ 
                fieldLabel: '登录名', 
                name: 'userid', 
                id: 'userid', 
				width: 180,
                allowBlank: false ,
                blankText:'登录名不可为空',
	            vtype: 'isNumberAlphaUnderlineChineseNotStartNumber'
            },{ 
                fieldLabel: '密码', 
                name: 'password',
                id: 'password',
                inputType: 'password', 
				width: 180,
                allowBlank: false ,
                blankText:'密码不可为空',
                vtype:'isNumberAlphaUnderline'
            }
        ],
        
        buttons:[{ 
                text: '登录',
                formBind: true,	 
                handler: login 
            },{
				text: '重置',
				handler:  function cancel(){
					Ext.getCmp('loginForm').form.reset(); 
				}
			}]  
            
    });
  
	function login() { 
       	if (loginForm.form.isValid()) {
        	loginForm.form.submit({
         		url: '<%=request.getContextPath()%>/edu.ccut.saturn.authority.impl::/loginModule/action/LoginJson.action', 
              		success : function(from, action) {
              			var myResult = Ext.util.JSON.decode(action.response.responseText);
              			if (myResult.success == 'true') {
              				window.location = "<%=request.getContextPath()%>/admin/web/main.jsp";
                          } else {
                          	Ext.MessageBox.show({
                                  title: '登录失败',
                                  msg: '账号或密码不正确！',
                                  buttons: Ext.MessageBox.OK,
                                  icon: Ext.MessageBox.ERROR
                              });
                          }
                      },
                      failure : function(form, action) {
                      	Ext.MessageBox.show({
                                 title: '登录失败',
                                 msg: '登录请求发送失败！',
                                 buttons: Ext.MessageBox.OK,
                                 icon: Ext.MessageBox.ERROR
                             });
                      },
              		waitMsg:'登录中...'
             	}
           );
       }
	}
 
    var win = new Ext.Window({
        layout:'fit',
        width:300,
        height:160,
        closable: false,
        resizable: false,
        plain: true,
        border: false,
        items: [loginForm]
	});

	win.show(); 
	
	document.getElementById('userid').maxLength = 10;
	document.getElementById('password').maxLength = 16;
/*	
	loginForm.getForm().getEl().dom.password.onkeydown = function(e){
		if(e.keyCode == 13){
			login();
		}
	};*/

});
</script>
</head>
<body>
<div></div>
</body>
</html>
